//
//  TestSecond.m
//  验证码倒计时
//
//  Created by 宋飞龙 on 15/8/31.
//  Copyright (c) 2015年 宋飞龙. All rights reserved.
//

#import "TestSecond.h"

@interface TestSecond () {
    NSTimer * timer;
    int seconds;
}

@end

@implementation TestSecond

-(void)startTime {
    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerStart:) userInfo:nil repeats:YES];
    seconds = 60;
}

-(void)timerStart:(NSTimer *)theTimer {
    if (seconds == 0) {
        [theTimer invalidate];
        seconds = 60;
        [self setTitle:@"重新发送" forState: UIControlStateNormal];
        [self setEnabled:YES];
    }else{
        seconds--;
        NSString *title = [NSString stringWithFormat:@"%0.2d秒后重发",seconds];
        [self setEnabled:NO];
        [self setTitle:title forState:UIControlStateNormal];
    }
}

@end
